home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Publish / E-G / EGREP15.sit / egrep-1.5 / grep-src / dfa.h < prev    next >
Encoding:
Text File  |  1991-10-20  |  22.0 KB  |  556 lines  |  [TEXT/MPS ]

  1. /*  This file has been changed-- it is not the standard FSF version.
  2.  
  3.                          Oct 1991.  */
  4.  
  5.  
  6. /* dfa.h - declarations for GNU deterministic regexp compiler
  7.    Copyright (C) 1988 Free Software Foundation, Inc.
  8.                       Written June, 1988 by Mike Haertel
  9.  
  10.                NO WARRANTY
  11.  
  12.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  13. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  14. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  15. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  16. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  17. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  19. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  20. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  21. CORRECTION.
  22.  
  23.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  24. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  25. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  26. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  27. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  28. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  29. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  30. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  31. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  32. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  33.  
  34.         GENERAL PUBLIC LICENSE TO COPY
  35.  
  36.   1. You may copy and distribute verbatim copies of this source file
  37. as you receive it, in any medium, provided that you conspicuously and
  38. appropriately publish on each copy a valid copyright notice "Copyright
  39.  (C) 1988 Free Software Foundation, Inc."; and include following the
  40. copyright notice a verbatim copy of the above disclaimer of warranty
  41. and of this License.  You may charge a distribution fee for the
  42. physical act of transferring a copy.
  43.  
  44.   2. You may modify your copy or copies of this source file or
  45. any portion of it, and copy and distribute such modifications under
  46. the terms of Paragraph 1 above, provided that you also do the following:
  47.  
  48.     a) cause the modified files to carry prominent notices stating
  49.     that you changed the files and the date of any change; and
  50.  
  51.     b) cause the whole of any work that you distribute or publish,
  52.     that in whole or in part contains or is a derivative of this
  53.     program or any part thereof, to be licensed at no charge to all
  54.     third parties on terms identical to those contained in this
  55.     License Agreement (except that you may choose to grant more extensive
  56.     warranty protection to some or all third parties, at your option).
  57.  
  58.     c) You may charge a distribution fee for the physical act of
  59.     transferring a copy, and you may at your option offer warranty
  60.     protection in exchange for a fee.
  61.  
  62. Mere aggregation of another unrelated program with this program (or its
  63. derivative) on a volume of a storage or distribution medium does not bring
  64. the other program under the scope of these terms.
  65.  
  66.   3. You may copy and distribute this program or any portion of it in
  67. compiled, executable or object code form under the terms of Paragraphs
  68. 1 and 2 above provided that you do the following:
  69.  
  70.     a) accompany it with the complete corresponding machine-readable
  71.     source code, which must be distributed under the terms of
  72.     Paragraphs 1 and 2 above; or,
  73.  
  74.     b) accompany it with a written offer, valid for at least three
  75.     years, to give any third party free (except for a nominal
  76.     shipping charge) a complete machine-readable copy of the
  77.     corresponding source code, to be distributed under the terms of
  78.     Paragraphs 1 and 2 above; or,
  79.  
  80.     c) accompany it with the information you received as to where the
  81.     corresponding source code may be obtained.  (This alternative is
  82.     allowed only for noncommercial distribution and only if you
  83.     received the program in object code or executable form alone.)
  84.  
  85. For an executable file, complete source code means all the source code for
  86. all modules it contains; but, as a special exception, it need not include
  87. source code for modules which are standard libraries that accompany the
  88. operating system on which the executable file runs.
  89.  
  90.   4. You may not copy, sublicense, distribute or transfer this program
  91. except as expressly provided under this License Agreement.  Any attempt
  92. otherwise to copy, sublicense, distribute or transfer this program is void and
  93. your rights to use the program under this License agreement shall be
  94. automatically terminated.  However, parties who have received computer
  95. software programs from you with this License Agreement will not have
  96. their licenses terminated so long as such parties remain in full compliance.
  97.  
  98.   5. If you wish to incorporate parts of this program into other free
  99. programs whose distribution conditions are different, write to the Free
  100. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  101. worked out a simple rule that can be stated here, but we will often permit
  102. this.  We will be guided by the two goals of preserving the free status of
  103. all derivatives our free software and of promoting the sharing and reuse of
  104. software.
  105.  
  106.  
  107. In other words, you are welcome to use, share and improve this program.
  108. You are forbidden to forbid anyone else to use, share and improve
  109. what you give them.   Help stamp out software-hoarding!  */
  110.  
  111.  
  112. #ifdef USG
  113. #include <string.h>
  114. extern char *index();
  115. #else
  116. #include <strings.h>
  117. extern char *strchr(), *strrchr(), *memcpy();
  118. #endif
  119.  
  120. #ifdef __STDC__
  121.  
  122. /* Missing include files for GNU C. */
  123. #include <stdlib.h>
  124.  
  125. extern void *realloc(void *, size_t);
  126. extern void free(void *);
  127.  
  128. extern char *bcopy(), *bzero();
  129.  
  130. #define isascii(c) (c < 128)
  131. #ifdef SOMEDAY
  132. #define ISALNUM(c) isalnum(c)
  133. #define ISALPHA(c) isalpha(c)
  134. #define ISUPPER(c) isupper(c)
  135. #else
  136. #define ISALNUM(c) (isascii(c) && isalnum(c))
  137. #define ISALPHA(c) (isascii(c) && isalpha(c))
  138. #define ISUPPER(c) (isascii(c) && isupper(c))
  139. #endif
  140.  
  141. #else /* ! __STDC__ */
  142.  
  143. #define const
  144. typedef int size_t;
  145. extern char *calloc(), *malloc(), *realloc();
  146. extern void free();
  147.  
  148. extern char *bcopy(), *bzero();
  149.  
  150. #define ISALNUM(c) (isascii(c) && isalnum(c))
  151. #define ISALPHA(c) (isascii(c) && isalpha(c))
  152. #define ISUPPER(c) (isascii(c) && isupper(c))
  153.  
  154. #endif /* ! __STDC__ */
  155.  
  156. /* 1 means plain parentheses serve as grouping, and backslash
  157.      parentheses are needed for literal searching.
  158.    0 means backslash-parentheses are grouping, and plain parentheses
  159.      are for literal searching.  */
  160. #define RE_NO_BK_PARENS 1
  161.  
  162. /* 1 means plain | serves as the "or"-operator, and \| is a literal.
  163.    0 means \| serves as the "or"-operator, and | is a literal.  */
  164. #define RE_NO_BK_VBAR 2
  165.  
  166. /* 0 means plain + or ? serves as an operator, and \+, \? are literals.
  167.    1 means \+, \? are operators and plain +, ? are literals.  */
  168. #define RE_BK_PLUS_QM 4
  169.  
  170. /* 1 means | binds tighter than ^ or $.
  171.    0 means the contrary.  */
  172. #define RE_TIGHT_VBAR 8
  173.  
  174. /* 1 means treat \r as an _OR operator  newline changed 
  175.    0 means treat it as a normal character */
  176. #define RE_NEWLINE_OR 16
  177.  
  178. /* 0 means that a special characters (such as *, ^, and $) always have
  179.      their special meaning regardless of the surrounding context.
  180.    1 means that special characters may act as normal characters in some
  181.      contexts.  Specifically, this applies to:
  182.     ^ - only special at the beginning, or after ( or |
  183.     $ - only special at the end, or before ) or |
  184.     *, +, ? - only special when not after the beginning, (, or | */
  185. #define RE_CONTEXT_INDEP_OPS 32
  186.  
  187. /* Now define combinations of bits for the standard possibilities.  */
  188. #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS)
  189. #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  190. #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  191. #define RE_SYNTAX_EMACS
  192.  
  193. /* Number of bits in an unsigned char. */
  194. #define CHARBITS 8
  195.  
  196. /* First integer value that is greater than any character code. */
  197. #define _NOTCHAR (1 << CHARBITS)
  198.  
  199. /* INTBITS need not be exact, just a lower bound. */
  200. #define INTBITS (CHARBITS * sizeof (int))
  201.  
  202. /* Number of ints required to hold a bit for every character. */
  203. #define _CHARSET_INTS ((_NOTCHAR + INTBITS - 1) / INTBITS)
  204.  
  205. /* Sets of unsigned characters are stored as bit vectors in arrays of ints. */
  206. typedef int _charset[_CHARSET_INTS];
  207.  
  208. /* The regexp is parsed into an array of tokens in postfix form.  Some tokens
  209.    are operators and others are terminal symbols.  Most (but not all) of these
  210.    codes are returned by the lexical analyzer. */
  211. #ifdef __STDC__
  212.  
  213. typedef enum
  214. {
  215.   _END = -1,            /* _END is a terminal symbol that matches the
  216.                    end of input; any value of _END or less in
  217.                    the parse tree is such a symbol.  Accepting
  218.                    states of the DFA are those that would have
  219.                    a transition on _END. */
  220.  
  221.   /* Ordinary character values are terminal symbols that match themselves. */
  222.  
  223.   _EMPTY = _NOTCHAR,        /* _EMPTY is a terminal symbol that matches
  224.                    the empty string. */
  225.  
  226.   _BACKREF,            /* _BACKREF is generated by \<digit>; it
  227.                    it not completely handled.  If the scanner
  228.                    detects a transition on backref, it returns
  229.                    a kind of "semi-success" indicating that
  230.                    the match will have to be verified with
  231.                    a backtracking matcher. */
  232.  
  233.   _BEGLINE,            /* _BEGLINE is a terminal symbol that matches
  234.                    the empty string if it is at the beginning
  235.                    of a line. */
  236.  
  237.   _ALLBEGLINE,            /* _ALLBEGLINE is a terminal symbol that
  238.                    matches the empty string if it is at the
  239.                    beginning of a line; _ALLBEGLINE applies
  240.                    to the entire regexp and can only occur
  241.                    as the first token thereof.  _ALLBEGLINE
  242.                    never appears in the parse tree; a _BEGLINE
  243.                    is prepended with _CAT to the entire
  244.                    regexp instead. */
  245.  
  246.   _ENDLINE,            /* _ENDLINE is a terminal symbol that matches
  247.                    the empty string if it is at the end of
  248.                    a line. */
  249.  
  250.   _ALLENDLINE,            /* _ALLENDLINE is to _ENDLINE as _ALLBEGLINE
  251.                    is to _BEGLINE. */
  252.  
  253.   _BEGWORD,            /* _BEGWORD is a terminal symbol that matches
  254.                    the empty string if it is at the beginning
  255.                    of a word. */
  256.  
  257.   _ENDWORD,            /* _ENDWORD is a terminal symbol that matches
  258.                    the empty string if it is at the end of
  259.                    a word. */
  260.  
  261.   _LIMWORD,            /* _LIMWORD is a terminal symbol that matches
  262.                    the empty string if it is at the beginning
  263.                    or the end of a word. */
  264.  
  265.   _NOTLIMWORD,            /* _NOTLIMWORD is a terminal symbol that
  266.                    matches the empty string if it is not at
  267.                    the beginning or end of a word. */
  268.  
  269.   _QMARK,            /* _QMARK is an operator of one argument that
  270.                    matches zero or one occurences of its
  271.                    argument. */
  272.  
  273.   _STAR,            /* _STAR is an operator of one argument that
  274.                    matches the Kleene closure (zero or more
  275.                    occurrences) of its argument. */
  276.  
  277.   _PLUS,            /* _PLUS is an operator of one argument that
  278.                    matches the positive closure (one or more
  279.                    occurrences) of its argument. */
  280.  
  281.   _CAT,                /* _CAT is an operator of two arguments that
  282.                    matches the concatenation of its
  283.                    arguments.  _CAT is never returned by the
  284.                    lexical analyzer. */
  285.  
  286.   _OR,                /* _OR is an operator of two arguments that
  287.                    matches either of its arguments. */
  288.  
  289.   _LPAREN,            /* _LPAREN never appears in the parse tree,
  290.                    it is only a lexeme. */
  291.  
  292.   _RPAREN,            /* _RPAREN never appears in the parse tree. */
  293.  
  294.   _SET                /* _SET and (and any value greater) is a
  295.                    terminal symbol that matches any of a
  296.                    class of characters. */
  297. } _token;
  298.  
  299. #else /* ! __STDC__ */
  300.  
  301. typedef short _token;
  302.  
  303. #define _END -1
  304. #define _EMPTY _NOTCHAR
  305. #define _BACKREF (_EMPTY + 1)
  306. #define _BEGLINE (_EMPTY + 2)
  307. #define _ALLBEGLINE (_EMPTY + 3)
  308. #define _ENDLINE (_EMPTY + 4)
  309. #define _ALLENDLINE (_EMPTY + 5)
  310. #define _BEGWORD (_EMPTY + 6)
  311. #define _ENDWORD (_EMPTY + 7)
  312. #define _LIMWORD (_EMPTY + 8)
  313. #define _NOTLIMWORD (_EMPTY + 9)
  314. #define _QMARK (_EMPTY + 10)
  315. #define _STAR (_EMPTY + 11)
  316. #define _PLUS (_EMPTY + 12)
  317. #define _CAT (_EMPTY + 13)
  318. #define _OR (_EMPTY + 14)
  319. #define _LPAREN (_EMPTY + 15)
  320. #define _RPAREN (_EMPTY + 16)
  321. #define _SET (_EMPTY + 17)
  322.  
  323. #endif /* ! __STDC__ */
  324.  
  325. /* Sets are stored in an array in the compiled regexp; the index of the
  326.    array corresponding to a given set token is given by _SET_INDEX(t). */
  327. #define _SET_INDEX(t) ((t) - _SET)
  328.  
  329. /* Sometimes characters can only be matched depending on the surrounding
  330.    context.  Such context decisions depend on what the previous character
  331.    was, and the value of the current (lookahead) character.  Context
  332.    dependent constraints are encoded as 8 bit integers.  Each bit that
  333.    is set indicates that the constraint succeeds in the corresponding
  334.    context.
  335.  
  336.    bit 7 - previous and current are newlines
  337.    bit 6 - previous was newline, current isn't
  338.    bit 5 - previous wasn't newline, current is
  339.    bit 4 - neither previous nor current is a newline
  340.    bit 3 - previous and current are word-constituents
  341.    bit 2 - previous was word-constituent, current isn't
  342.    bit 1 - previous wasn't word-constituent, current is
  343.    bit 0 - neither previous nor current is word-constituent
  344.  
  345.    Word-constituent characters are those that satisfy isalnum().
  346.  
  347.    The macro _SUCCEEDS_IN_CONTEXT determines whether a a given constraint
  348.    succeeds in a particular context.  Prevn is true if the previous character
  349.    was a newline, currn is true if the lookahead character is a newline.
  350.    Prevl and currl similarly depend upon whether the previous and current
  351.    characters are word-constituent letters. */
  352. #define _MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \
  353.   ((constraint) & 1 << ((prevn) ? 2 : 0) + ((currn) ? 1 : 0) + 4)
  354. #define _MATCHES_LETTER_CONTEXT(constraint, prevl, currl) \
  355.   ((constraint) & 1 << ((prevl) ? 2 : 0) + ((currl) ? 1 : 0))
  356. #define _SUCCEEDS_IN_CONTEXT(constraint, prevn, currn, prevl, currl) \
  357.   (_MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn)             \
  358.    && _MATCHES_LETTER_CONTEXT(constraint, prevl, currl))
  359.  
  360. /* The following macros give information about what a constraint depends on. */
  361. #define _PREV_NEWLINE_DEPENDENT(constraint) \
  362.   (((constraint) & 0xc0) >> 2 != ((constraint) & 0x30))
  363. #define _PREV_LETTER_DEPENDENT(constraint) \
  364.   (((constraint) & 0x0c) >> 2 != ((constraint) & 0x03))
  365.  
  366. /* Tokens that match the empty string subject to some constraint actually
  367.    work by applying that constraint to determine what may follow them,
  368.    taking into account what has gone before.  The following values are
  369.    the constraints corresponding to the special tokens previously defined. */
  370. #define _NO_CONSTRAINT 0xff
  371. #define _BEGLINE_CONSTRAINT 0xcf
  372. #define _ENDLINE_CONSTRAINT 0xaf
  373. #define _BEGWORD_CONSTRAINT 0xf2
  374. #define _ENDWORD_CONSTRAINT 0xf4
  375. #define _LIMWORD_CONSTRAINT 0xf6
  376. #define _NOTLIMWORD_CONSTRAINT 0xf9
  377.  
  378. /* States of the recognizer correspond to sets of positions in the parse
  379.    tree, together with the constraints under which they may be matched.
  380.    So a position is encoded as an index into the parse tree together with
  381.    a constraint. */
  382. typedef struct
  383. {
  384.   unsigned index;        /* Index into the parse array. */
  385.   unsigned constraint;        /* Constraint for matching this position. */
  386. } _position;
  387.  
  388. /* Sets of positions are stored as arrays. */
  389. typedef struct
  390. {
  391.   _position *elems;        /* Elements of this position set. */
  392.   int nelem;            /* Number of elements in this set. */
  393. } _position_set;
  394.  
  395. /* A state of the regexp consists of a set of positions, some flags,
  396.    and the token value of the lowest-numbered position of the state that
  397.    contains an _END token. */
  398. typedef struct
  399. {
  400.   int hash;            /* Hash of the positions of this state. */
  401.   _position_set elems;        /* Positions this state could match. */
  402.   char newline;            /* True if previous state matched newline. */
  403.   char letter;            /* True if previous state matched a letter. */
  404.   char backref;            /* True if this state matches a \<digit>. */
  405.   unsigned char constraint;    /* Constraint for this state to accept. */
  406.   int first_end;        /* Token value of the first _END in elems. */
  407. } _dfa_state;
  408.  
  409. /* If an r.e. is at most MUST_MAX characters long, we look for a string which
  410.    must appear in it; whatever's found is dropped into the struct reg. */
  411.  
  412. #define MUST_MAX    50
  413.  
  414. /* A compiled regular expression. */
  415. struct regexp
  416. {
  417.   /* Stuff built by the scanner. */
  418.   _charset *charsets;        /* Array of character sets for _SET tokens. */
  419.   int cindex;            /* Index for adding new charsets. */
  420.   int calloc;            /* Number of charsets currently allocated. */
  421.  
  422.   /* Stuff built by the parser. */
  423.   _token *tokens;        /* Postfix parse array. */
  424.   int tindex;            /* Index for adding new tokens. */
  425.   int talloc;            /* Number of tokens currently allocated. */
  426.   int depth;            /* Depth required of an evaluation stack
  427.                    used for depth-first traversal of the
  428.                    parse tree. */
  429.   int nleaves;            /* Number of leaves on the parse tree. */
  430.   int nregexps;            /* Count of parallel regexps being built
  431.                    with regparse(). */
  432.  
  433.   /* Stuff owned by the state builder. */
  434.   _dfa_state *states;        /* States of the regexp. */
  435.   int sindex;            /* Index for adding new states. */
  436.   int salloc;            /* Number of states currently allocated. */
  437.  
  438.   /* Stuff built by the structure analyzer. */
  439.   _position_set *follows;    /* Array of follow sets, indexed by position
  440.                    index.  The follow of a position is the set
  441.                    of positions containing characters that
  442.                    could conceivably follow a character
  443.                    matching the given position in a string
  444.                    matching the regexp.  Allocated to the
  445.                    maximum possible position index. */
  446.   int searchflag;        /* True if we are supposed to build a searching
  447.                    as opposed to an exact matcher.  A searching
  448.                    matcher finds the first and shortest string
  449.                    matching a regexp anywhere in the buffer,
  450.                    whereas an exact matcher finds the longest
  451.                    string matching, but anchored to the
  452.                    beginning of the buffer. */
  453.  
  454.   /* Stuff owned by the executor. */
  455.   int tralloc;            /* Number of transition tables that have
  456.                    slots so far. */
  457.   int trcount;            /* Number of transition tables that have
  458.                    actually been built. */
  459.   int **trans;            /* Transition tables for states that can
  460.                    never accept.  If the transitions for a
  461.                    state have not yet been computed, or the
  462.                    state could possibly accept, its entry in
  463.                    this table is NULL. */
  464.   int **realtrans;        /* Trans always points to realtrans + 1; this
  465.                    is so trans[-1] can contain NULL. */
  466.   int **fails;            /* Transition tables after failing to accept
  467.                    on a state that potentially could do so. */
  468.   int *success;            /* Table of acceptance conditions used in
  469.                    regexecute and computed in build_state. */
  470.   int *newlines;        /* Transitions on newlines.  The entry for a
  471.                    newline in any transition table is always
  472.                    -1 so we can count lines without wasting
  473.                    too many cycles.  The transition for a
  474.                    newline is stored separately and handled
  475.                    as a special case.  Newline is also used
  476.                    as a sentinel at the end of the buffer. */
  477.   char must[MUST_MAX];
  478.   int mustn;
  479. };
  480.  
  481. /* Some macros for user access to regexp internals. */
  482.  
  483. /* ACCEPTING returns true if s could possibly be an accepting state of r. */
  484. #define ACCEPTING(s, r) ((r).states[s].constraint)
  485.  
  486. /* ACCEPTS_IN_CONTEXT returns true if the given state accepts in the
  487.    specified context. */
  488. #define ACCEPTS_IN_CONTEXT(prevn, currn, prevl, currl, state, reg) \
  489.   _SUCCEEDS_IN_CONTEXT((reg).states[state].constraint,           \
  490.                prevn, currn, prevl, currl)
  491.  
  492. /* FIRST_MATCHING_REGEXP returns the index number of the first of parallel
  493.    regexps that a given state could accept.  Parallel regexps are numbered
  494.    starting at 1. */
  495. #define FIRST_MATCHING_REGEXP(state, reg) (-(reg).states[state].first_end)
  496.  
  497. /* Entry points. */
  498.  
  499. #ifdef __STDC__
  500.  
  501. /* Regsyntax() takes two arguments; the first sets the syntax bits described
  502.    earlier in this file, and the second sets the case-folding flag. */
  503. extern void regsyntax(int, int);
  504.  
  505. /* Compile the given string of the given length into the given struct regexp.
  506.    Final argument is a flag specifying whether to build a searching or an
  507.    exact matcher. */
  508. extern void regcompile(const char *, size_t, struct regexp *, int);
  509.  
  510. /* Execute the given struct regexp on the buffer of characters.  The
  511.    first char * points to the beginning, and the second points to the
  512.    first character after the end of the buffer, which must be a writable
  513.    place so a sentinel end-of-buffer marker can be stored there.  The
  514.    second-to-last argument is a flag telling whether to allow newlines to
  515.    be part of a string matching the regexp.  The next-to-last argument,
  516.    if non-NULL, points to a place to increment every time we see a
  517.    newline.  The final argument, if non-NULL, points to a flag that will
  518.    be set if further examination by a backtracking matcher is needed in
  519.    order to verify backreferencing; otherwise the flag will be cleared.
  520.    Returns NULL if no match is found, or a pointer to the first
  521.    character after the first & shortest matching string in the buffer. */
  522. extern char *regexecute(struct regexp *, char *, char *, int, int *, int *);
  523.  
  524. /* Free the storage held by the components of a struct regexp. */
  525. extern void regfree(struct regexp *);
  526.  
  527. /* Entry points for people who know what they're doing. */
  528.  
  529. /* Initialize the components of a struct regexp. */
  530. extern void reginit(struct regexp *);
  531.  
  532. /* Incrementally parse a string of given length into a struct regexp. */
  533. extern void regparse(const char *, size_t, struct regexp *);
  534.  
  535. /* Analyze a parsed regexp; second argument tells whether to build a searching
  536.    or an exact matcher. */
  537. extern void reganalyze(struct regexp *, int);
  538.  
  539. /* Compute, for each possible character, the transitions out of a given
  540.    state, storing them in an array of integers. */
  541. extern void regstate(int, struct regexp *, int []);
  542.  
  543. /* Error handling. */
  544.  
  545. /* Regerror() is called by the regexp routines whenever an error occurs.  It
  546.    takes a single argument, a NUL-terminated string describing the error.
  547.    The default regerror() prints the error message to stderr and exits.
  548.    The user can provide a different regfree() if so desired. */
  549. extern void regerror(char *);
  550.  
  551. #else /* ! __STDC__ */
  552. extern void regsyntax(), regcompile(), regfree(), reginit(), regparse();
  553. extern void reganalyze(), regstate(), regerror();
  554. extern char *regexecute();
  555. #endif
  556.